package cn.powerone.scm.controller;

import java.io.IOException;
import java.util.List;

import cn.powerone.scm.pojo.bo.ScmInquiriesInOut;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmInquiriesOut;
import cn.powerone.scm.service.IScmInquiriesOutService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 供应商询价单Controller
 * 
 * @author PowerOne
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/scm/scmInquiriesOut")
public class ScmInquiriesOutController extends BaseController
{
    @Autowired
    private IScmInquiriesOutService scmInquiriesOutService;

    /**
     * 查询供应商询价单列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmInquiriesOut scmInquiriesOut)
    {
        startPage();
        List<ScmInquiriesOut> list = scmInquiriesOutService.selectScmInquiriesOutList(scmInquiriesOut);
        return getDataTable(list);
    }

    /**
     * 导出供应商询价单列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:export')")
    @Log(title = "供应商询价单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmInquiriesOut scmInquiriesOut)
    {
        List<ScmInquiriesOut> list = scmInquiriesOutService.selectScmInquiriesOutList(scmInquiriesOut);
        ExcelUtil<ScmInquiriesOut> util = new ExcelUtil<ScmInquiriesOut>(ScmInquiriesOut.class);
        util.exportExcel(response, list, "供应商询价单数据");
    }

    /**
     * 生成供应商询价单列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:generate')")
    @Log(title = "询价单", businessType = BusinessType.GENORDER)
    @PostMapping("/generate")
    public void generate(HttpServletResponse response, ScmInquiriesOut scmInquiriesOut) throws IOException {
        List<ScmInquiriesOut> list = scmInquiriesOutService.selectScmInquiriesOutList(scmInquiriesOut);
        scmInquiriesOutService.exportExcelByTemplate(response, list, "供应商询价模板表25.9.10.xlsx");
    }

    /**
     * 获取供应商询价单详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmInquiriesOutService.selectScmInquiriesOutById(id));
    }

    /**
     * 新增供应商询价单
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:add')")
    @Log(title = "供应商询价单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmInquiriesOut scmInquiriesOut)
    {
        return toAjax(scmInquiriesOutService.insertScmInquiriesOut(scmInquiriesOut));
    }
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:add')")
    @Log(title = "供应商询价单", businessType = BusinessType.INSERT)
    @PostMapping("/fromIn")
    public AjaxResult addFromIn(@RequestBody ScmInquiriesInOut scmInquiriesInOut)
    {
        return toAjax(scmInquiriesOutService.insertScmInquiriesOutFromIn(scmInquiriesInOut));
    }

    /**
     * 修改供应商询价单
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:edit')")
    @Log(title = "供应商询价单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmInquiriesOut scmInquiriesOut)
    {
        return toAjax(scmInquiriesOutService.updateScmInquiriesOut(scmInquiriesOut));
    }

    /**
     * 删除供应商询价单
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInquiriesOut:remove')")
    @Log(title = "供应商询价单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmInquiriesOutService.deleteScmInquiriesOutByIds(ids));
    }
}
